package cn.jiyun.controller;

import cn.jiyun.pojo.Goods;
import cn.jiyun.pojo.Page;
import cn.jiyun.pojo.Range;
import cn.jiyun.util.WriterUtil;
import cn.jiyun.service.GoodsService;


import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Controller
public class GoodsController {
    @Autowired(required = false)
    private GoodsService goodsService;

    //运营角色分页
    @RequestMapping("page")
    public Page getPage(@RequestParam("page") int page, @RequestParam("size") int size,
                        @RequestParam("name") String name) throws Exception {
        PageHelper.startPage(page,size);
        List<Goods> list=new ArrayList<>();
        if (name!=null&&!"".equals(name)){
            list = goodsService.getSp(name);
        }else {
            list=goodsService.getAll();
        }
        PageInfo<Goods> info = new PageInfo<>(list);
        Page page1 = new Page(info.getPages(), info.getList());
        return page1;
    }
    //商品中心角色分页
    @RequestMapping("pagej")
    public Page getPageb(@RequestParam("page") int page, @RequestParam("size") int size) throws Exception {
        PageHelper.startPage(page,size);
        List<Goods> list=new ArrayList<>();
        list=goodsService.getAllby();
        PageInfo<Shop> info = new PageInfo<>(list);
        Page page1 = new Page(info.getPages(), info.getList());
        return page1;
    }
}
